﻿Imports System.Data.OleDb
Public Class Viewpicture
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not User.Identity.Name = "" Then
            tb_comment.Visible = True
            btn_comment.Visible = True
        Else
            Response.Redirect("Account/Login.aspx")
        End If

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_comment.Click
        Dim sql As String = "INSERT INTO picturecomments (comment, pictureid, dinerid) VALUES(@a1,@a2,@a3)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("mercedesbenzconnectionstring").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@a1", tb_comment.Text)
        cmd.Parameters.AddWithValue("@a2", Request.Params("id"))
        cmd.Parameters.AddWithValue("@a3", User.Identity.Name)

        conn.Open()

        If (cmd.ExecuteNonQuery()) Then
            conn.Close()
            cmd.Dispose()
            conn.Dispose()
            MsgBox("comment saved!!!", MsgBoxStyle.Exclamation)
            Response.Redirect("viewpicture.aspx?id=" & Request.Params("id"))
        Else
            MsgBox("Sorry, your comment has not been saved.Check and be sure there s no mistake somewhere!!!", MsgBoxStyle.Exclamation)
            tb_comment.Focus()
            Return
        End If
    End Sub
End Class